#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

//机器人的运动范围，递归，类似前一题
int getSum(int n)
{
    int s = 0;
    while (n > 0)
    {
        s += n % 10;
        n /= 10;
    }
    return s;
}

void helper(int &k, int &rows, int &cols, int i, int j, int &ans, vector<vector<bool>> &mark)
{
    if (i < 0 || i >= rows || j < 0 || j >= cols)
    {
        return;
    }
    if (mark[i][j])
    {
        return;
    }
    mark[i][j] = true;
    if (getSum(i) + getSum(j) > k)
    {
        return;
    }
    ++ans;
    helper(k, rows, cols, i + 1, j, ans, mark);
    helper(k, rows, cols, i, j + 1, ans, mark);
}
int movingCount(int k, int rows, int cols)
{
    int ans = 0;
    vector<vector<bool>> mark(rows, vector<bool>(cols, false));
    helper(k, rows, cols, 0, 0, ans, mark);
    return ans;
}

void test()
{
}

int main()
{
    test();
    return 0;
}